home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-14 | 5.5 KB | 199 lines | [TEXT/KAHL] |
- /******************************************************************************
- CDemoTable.c
-
-
- SUPERCLASS = CTable
-
- Copyright © 1991 Symantec Corporation. All rights reserved.
-
- This is a demo of the TCL class CTable. CTable provides the
- foundation for scrolling list and spreadsheet-like panes.
- It provides only visual appearance - storage for the contents
- of cells must be provided in CTable subclasses.
-
- CDemoTable doesn't store any data for the cells, but it does
- show a way to provide some features not directly supported by
- CTable. It adds row and column headings, and a user interface
- for resizing rows and columns. Undo for row and column resizing
- is also supported.
-
- Printing the row and column headings, and row and column selection
- via clicking in the label area is not supported.
-
- This class relies on CTableScroller and CTableLabels for support
- for syncronized scrolling of the row and column labels.
-
-
- ******************************************************************************/
-
- #include "CDemoTable.h"
- #include "CTableLabels.h"
- #include "CTableScroller.h"
- #include "CWindow.h"
- #include "Commands.h"
-
- #define kPlusCursor 1024 // resource ID of 'CURS' cursor
-
- extern RgnHandle gUtilRgn; // a global utility region
-
- /******************************************************************************
- IDemoTable
-
- Initialize the demo table.
- ******************************************************************************/
-
- void CDemoTable::IDemoTable(CTableScroller *anEnclosure, CBureaucrat *aSupervisor,
- CTableLabels *rowLabels, CTableLabels *colLabels)
- {
- Rect delta;
-
- // call CTable's initialization method. Note that we set the
- // size to zero, because we are going to fit it to its enclosure
-
- CTable::ITable(anEnclosure, aSupervisor, 0, 0, 0, 0,
- sizELASTIC, sizELASTIC);
-
- // Fit it to its enclosing view, which is the CTableScroller
-
- FitToEnclosure(TRUE, TRUE);
-
- // Move it down and to the right to make room for the row and col labels
-
- SetRect(&delta, 0, 0, -kRowLabelWidth, -kColLabelHeight);
- ChangeSize(&delta, FALSE);
- Offset(kRowLabelWidth, kColLabelHeight, FALSE);
-
- // Specify gray row and column borders for the cells
-
- SetRowBorders(1, patCopy, &qd.gray);
- SetColBorders(1, patCopy, &qd.gray);
-
- // set selection behavior so dragging selects rectangular areas
-
- SetSelectionFlags(selDragRects);
-
- itsRowLabels = rowLabels;
- itsColLabels = colLabels;
-
- // link the row and column labels to this table
-
- itsRowLabels->SetTable(this);
- itsColLabels->SetTable(this);
-
- // get our cursor
-
- plusCursor = GetCursor(kPlusCursor);
- FailNILRes(plusCursor);
-
- }
-
- /******************************************************************************
- GetCellText {OVERRIDE}
-
- We have no data, so just set the text to nothing.
-
- ******************************************************************************/
-
- void CDemoTable::GetCellText(Cell aCell, short availableWidth,
- StringPtr itsText)
- {
- Length(itsText) = 0;
- }
-
- /******************************************************************************
- Scroll {OVERRIDE}
-
- Normally you don't need to override Scroll. Here we do it
- in order to scroll the table along with the row or column headings
- ******************************************************************************/
-
- void CDemoTable::Scroll(long hDelta, long vDelta, Boolean redraw)
- {
- // CTableScroll::ScrollBits scrolls the table and headings
- // in a single ScrollRect call
-
- if (redraw)
- ((CTableScroller*)itsScrollPane)->ScrollBits(hDelta, vDelta);
-
- // Logically scroll the table and the appropriate labels,
- // without visually scrolling anything on-screen
-
- inherited::Scroll(hDelta, vDelta, FALSE);
- if (vDelta)
- itsRowLabels->Scroll(0, vDelta, FALSE);
- if (hDelta)
- itsColLabels->Scroll(hDelta, 0, FALSE);
-
- // redraw the window if requested.
-
- if (redraw)
- GetWindow()->Update();
- }
-
- /******************************************************************************
- AdjustCursor {OVERRIDE}
-
- Set the cursor to the standard spreadsheet plus cursor
- ******************************************************************************/
-
- void CDemoTable::AdjustCursor(Point where, RgnHandle mouseRgn)
- {
- LoadResource((Handle) plusCursor);
- if (*plusCursor)
- SetCursor(*plusCursor);
- }
-
- /******************************************************************************
- Draw {OVERRIDE}
-
- Normally you don't need to override CTable::Draw - you override
- DrawCell or GetCellText instead. Here we do it in order to fill
- the area outside the cells with a gray pattern.
-
- ******************************************************************************/
-
- void CDemoTable::Draw(Rect *area)
- {
- LongRect r;
- Rect qdRect;
- RgnHandle tmpRgn;
-
- // Get a region consisting of the area to be drawn
- // it is already in QuickDraw coordinates.
-
- RectRgn(gUtilRgn, area);
-
- // Get the intersection of the bounds and frame rects
- // This corresponds to the cells that are visible.
-
- SectLongRect(&bounds, &frame, &r);
-
- // Since that rect is in Frame coordinates, convert it to
- // a rect in QuickDraw coordinates
-
- FrameToQDR(&r, &qdRect);
-
- // Get a region consisting of the above rect
-
- tmpRgn = NewRgn();
- RectRgn(tmpRgn, &qdRect);
-
- // Subtract the visible cell area from the area to be drawn.
- // The region remaining gives use the area to be drawn outside
- // the bounds.
-
- DiffRgn(gUtilRgn, tmpRgn, tmpRgn);
-
- // If it ain't empty, fill it. Then dispose of the temporary region
-
- if (!EmptyRgn(tmpRgn))
- FillRgn(tmpRgn, &qd.gray);
-
- DisposeRgn(tmpRgn);
-
- // inherited::Draw draws the cells
-
- inherited::Draw(area);
-
- }
-